﻿
@{
    ViewData["Title"] = "Login";
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <link rel="stylesheet" type="text/css" href="~/css/index.css" />
    <link rel="stylesheet" type="text/javascript" href="~/js/jquery.min.js" />
</head>

@section Scripts
    {

    <script src="~/js/jquery-1.11.1.min.js"></script>
    <script type="text/javascript">

        layui.use(['layer'], function () {
            var layer = layui.layer;



            window.addEventListener("keydown", function (event) {
                if (event.keyCode == 13) {
                    login();
                }
            }, false);

            $(document).ready(function () {
                $("#login").click(function () {

                    login();

                });
            });

            function login() {
                var userName = $("#userName").val();
                var passWord = $("#passWord").val();
                if (userName.length < 1) {
                    alert("请输入登录名！");
                    return false;
                }
                if (passWord.length < 1) {
                    alert("请输入密码！");
                    return false;
                }
                console.log(userName);
                console.log(passWord);


                //axios.post('/Login/UserLogin', {
                //    Phone: userName,
                //    Password: passWord
                //})


                axios({
                    method: 'get',
                    url: '/Login/UserLogin',
                    //  contentType: 'application/x-www-form-urlencoded',
                    params: {
                        "Phone": userName,
                        "Password": passWord
                    }
                })
                    .then(function (response) {
                        console.log(response.data);
                        if (response.data.Code == 200) {
                            var index = layer.load(1, { shade: false });
                            console.log(response.data.result.access_token);

                            localStorage.setItem("X-TOKEN", response.data.result.access_token); //userName
                            localStorage.setItem("X-NAME", response.data.result.userName); //roleId
                            localStorage.setItem("X-ROLE", response.data.result.roleId);
                            localStorage.setItem("X-AreCode", response.data.result.roleArea);//
                            localStorage.setItem("X-UserUrl", response.data.result.headPortraitUrl);//
                            localStorage.setItem("X-UserId", response.data.result.userId);

                            //localStorage.setItem("X-ID", response.data.data.id);

                            //localStorage.setItem("X-ROLENAME", response.data.data.roleName);
                            window.location.href = '/Home/Index';
                        } else {
                            alert("登陆失败! " + response.data.msg);
                        }
                    })
                    .catch(function (error) {
                        console.log(error);
                    });
            }
        });

    </script>
}

<body>
    <div class="bg-top"></div>
    <div class="login">
        <div class="login-header"><img src="~/img/logo@2x.png"></div>
        <div class="login-title"><img src="~/img/houtai@2x.png" alt=""></div>
        <div class="login-main">
            <div class="account">
                <img src="~/img/user@2x.png" alt="">
                <input type="text" id="userName" placeholder="请输入您的账户ID" />
            </div>
            <div class="password">
                <img src="~/img/key@2x.png" alt="">
                <input type="password" id="passWord" placeholder="请输入您的密码" />
            </div>
            <div class="login-btn" id="login">登录</div>
        </div>
        <div class="footer">技术支持：  上海渔联网科技有限公司</div>
    </div>
</body>
</html>

